package samsung.sds.business.vdiManagementSystem.vdiManagement.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import samsung.sds.business.vdiManagementSystem.systemManagement.model.SystemInfoEntity;
import samsung.sds.business.vdiManagementSystem.vdiManagement.dao.VDIManagementMapper;
import samsung.sds.business.vdiManagementSystem.vdiManagement.model.VDIInfoEntity;
import samsung.sds.business.vdiManagementSystem.vdiManagement.model.VDISystemREndity;
import samsung.sds.business.vdiManagementSystem.vdiManagement.model.VDIUserEntity;
import samsung.sds.business.vdiManagementSystem.vdiManagement.model.VDIUserREntity;
import samsung.sds.business.vdiManagementSystem.vdiManagement.service.VDIManagementService;
import samsung.sds.system.common.baseQuery.AbstractBaseService;
import samsung.sds.system.common.baseQuery.BaseMapper;
import samsung.sds.system.common.baseQuery.model.PageData;
import samsung.sds.system.common.model.QueryParam;
import samsung.sds.userManagement.model.UserEntity;

@Service("vdiManagementServiceImpl")
@Transactional
public class VDIManagementServiceImpl extends AbstractBaseService<VDIInfoEntity> implements VDIManagementService {
	
	@Autowired
	private VDIManagementMapper vdiManagementMapper;
	
	@Override
	protected BaseMapper<VDIInfoEntity> getMapper() {
		return vdiManagementMapper;
	}

	public VDIInfoEntity findUniqueByProperty(VDIInfoEntity t) {
		return null;
	}

	public VDIInfoEntity findEntityById(String id) {
		return vdiManagementMapper.queryEntityById(id);
	}

	public int insertVdiInfo(VDIInfoEntity t) {
		return vdiManagementMapper.insertVdiInfo(t);
	}

	public int updateEntity(VDIInfoEntity t) {
		return vdiManagementMapper.updateEntity(t);
	}

	public int deleteEntityById(String id) {
		return 0;
	}

	public int deleteEntity(VDIInfoEntity t) {
		return vdiManagementMapper.deleteEntity(t);
	}

	public PageData<VDIInfoEntity> queryListPage(QueryParam param) {
		return null;
	}

	public List<VDIInfoEntity> queryList(QueryParam param) {
		return null;
	}
	
	public PageData<VDIInfoEntity> vdiInfoQueryListPage(QueryParam param) {
		List<VDIInfoEntity> vdiList = vdiManagementMapper.vdiInfoQueryListPage(param);
		for(int i=0;i<vdiList.size();i++){
			VDIInfoEntity temp = vdiList.get(i);
			List<UserEntity> vdiUsers = new ArrayList<UserEntity>();
			vdiUsers = vdiManagementMapper.queryVdiUsers(temp.getId());
			String users ="";
			for(int j=0;j<vdiUsers.size();j++){
				if(j==vdiUsers.size()-1){
					users = users+vdiUsers.get(j).getCn_name();
				}else{
					users = users+vdiUsers.get(j).getCn_name()+",";

				}
			}
			temp.setUsers(users);
			if(vdiUsers.size()<=0){
				temp.setStatus("未分配");
			}else{
				temp.setStatus("使用中");
			}
		}
		PageData<VDIInfoEntity> pd = new PageData<VDIInfoEntity>();
		pd.setQueryResult(vdiList);
		pd.setQueryParam(param);
		return pd;
	}

	public PageData<VDIInfoEntity> queryVdiInfoQueryListPage(QueryParam param) {
		List<VDIInfoEntity> vdiList = vdiManagementMapper.queryVdiInfoQueryListPage(param);
		for(int i=0;i<vdiList.size();i++){
			VDIInfoEntity temp = vdiList.get(i);
			List<UserEntity> vdiUsers = new ArrayList<UserEntity>();
			vdiUsers = vdiManagementMapper.queryVdiUsers(temp.getId());
			String users ="";
			for(int j=0;j<vdiUsers.size();j++){
				if(j==vdiUsers.size()-1){
					users = users+vdiUsers.get(j).getCn_name();
				}else{
					users = users+vdiUsers.get(j).getCn_name()+",";

				}
			}
			temp.setUsers(users);
			if(vdiUsers.size()<=0){
				temp.setStatus("未分配");
			}else{
				temp.setStatus("使用中");
			}
		}
		PageData<VDIInfoEntity> pd = new PageData<VDIInfoEntity>();
		pd.setQueryResult(vdiList);
		pd.setQueryParam(param);
		return pd;	
	}

	public int queryVdiSystemCount(String id) {
		
		return vdiManagementMapper.queryVdiSystemCount(id);
	}

	public List<UserEntity> queryVdiUsers(String id) {
		List<UserEntity> vdiusers = vdiManagementMapper.queryVdiUsers(id);
		return vdiusers;
	}

	public int updateVDIInfo(List<String> ids) {
		return vdiManagementMapper.updateVDIInfo(ids);
	}

	public int deleteVdiUser(List<String> ids) {
		return vdiManagementMapper.deleteVdiUser(ids);
	}

	public int deleteVdiSys(List<String> ids) {
		return vdiManagementMapper.deleteVdiSys(ids);
	}

	@Override
	public int insertVdiSystemR(VDISystemREndity vdiSystemREndity) {
		return vdiManagementMapper.insertVDISystemREndity(vdiSystemREndity);
	}

	@Override
	public int insertVdiUserR(VDIUserREntity vdiUserREntity) {
		return vdiManagementMapper.insertVDIUserREntity(vdiUserREntity);
	}

	@Override
	public int deleteVdiSystemR(VDISystemREndity vdiSystemREndity) {
		return vdiManagementMapper.deleteVdiSystemR(vdiSystemREndity);
	}

	@Override
	public int deleteVdiUserR(VDIUserREntity vdiUserREntity) {
		return vdiManagementMapper.deleteVdiUserR(vdiUserREntity);
	}

	@Override
	public VDIInfoEntity queryVdiListById(VDIInfoEntity vdiInfoEntity) {
		return vdiManagementMapper.queryVdiListById(vdiInfoEntity);
	}

	@Override
	public VDIInfoEntity queryVdiListByIp(VDIInfoEntity vdiInfoEntity) {
		return vdiManagementMapper.queryVdiListByIp(vdiInfoEntity);
	}

	@Override
	public List<UserEntity> queryVdiUserREndity(VDIInfoEntity vdiInfoEntity) {
		return vdiManagementMapper.queryVdiUserREndity(vdiInfoEntity);
	}

	@Override
	public List<SystemInfoEntity> queryVdiSystemREndity(VDIInfoEntity vdiInfoEntity) {
		return vdiManagementMapper.queryVdiSystemREndity(vdiInfoEntity);
	}

	@Override
	public int updateVDIInfoDetail(VDIInfoEntity vdiInfoEntity) {
		return vdiManagementMapper.updateVDIInfoDetail(vdiInfoEntity);
	}

	@Override
	public List<VDIInfoEntity> queryByLoginName(VDIInfoEntity vdiInfoEntity) {
		return vdiManagementMapper.queryByLoginName(vdiInfoEntity);
	}
	
	

}
